#ifndef _CONFIGPARSER_H
#define	_CONFIGPARSER_H

#include <stdio.h>
#include "configdata.h"
#include "yaml/yaml.h"

using namespace std;

class ConfigParser {
public:
  /**
   * Creates a new configuration parser using the specified filename. If an
   * error occurs while trying to open the file, an error is printed to
   * stderr (via perror()) and the ioerror field is set to true.
   * @param filename name of the configuration file.
   */
  ConfigParser(const char* filename);
  /** Destroys the instance, shuts down parser, etc. */
  ~ConfigParser();
  /**
   * Performs the actual parsing operation. Retrieve the result using
   * getConfig().
   * @return true if parsing was successful; false otherwise.
   */
  bool parse();
  /**
   * Returns the parsed config or NULL if none was parsed.
   * @return the configdata struct resulting from the parsing.
   */
  configdata* getConfig();
  
  /**
   * Indicates if an I/O error was encountered while reading the configuration
   * file.
   */
  bool ioerror;
  
private:
  yaml_parser_t parser;
  FILE* input;
  
  configdata* data;
};

#endif	/* _CONFIGPARSER_H */

